<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/7/10/0010
 * Time: 9:31
 */
namespace app\api\model;
vendor('alipay.wappay.service.AlipayTradeService');
vendor('alipay.wappay.buildermodel.AlipayTradeWapPayContentBuilder');
class Alipays extends BaseModel
{
    /*
     * 支付宝h5支付
     * */
    public $config;
    public  function __construct()
    {
        parent::__construct();
        $this->config = include './vendor/alipay/config.php';
    }

    public function alipay($orderInfo,$request_type)
    {
        header("Content-type:text/html;charset=utf-8");
        if (!empty($orderInfo['order'])&& trim($orderInfo['order'])!=""){
            //商户订单号，商户网站订单系统中唯一订单号，必填
            $out_trade_no = $orderInfo['order'];

            //订单名称，必填
            $subject = $orderInfo['WIDsubject'];

            //付款金额，必填
            $total_amount = $orderInfo['number'];

            //商品描述，可空
            $body = $orderInfo['remark'];

            //超时时间
            $timeout_express="1m";

            $payRequestBuilder = new \AlipayTradeWapPayContentBuilder();
            $payRequestBuilder->setBody($body);
            $payRequestBuilder->setSubject($subject);
            $payRequestBuilder->setOutTradeNo($out_trade_no);
            $payRequestBuilder->setTotalAmount($total_amount);
            $payRequestBuilder->setTimeExpress($timeout_express);
            $payResponse = new \AlipayTradeService($this->config);
            $result=$payResponse->wapPay($payRequestBuilder, $this->config['return_url'], $orderInfo['notify_url'],$request_type);
            return $result;
        }
    }
}